Skip to content

feat(parser): infer model from type hint #3181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 12, 2023
Merged

feat(parser): infer model from type hint #3181

merged 8 commits into from
Oct 12, 2023

Conversation

Tom01098
Copy link
Contributor

@Tom01098 Tom01098 commented Oct 7, 2023

Issue number: #3173

Summary

Changes

Made model optional in event_parser.

User experience

Users can now elide providing the model argument.

Before

from aws_lambda_powertools.utilities.parser import event_parser
from aws_lambda_powertools.utilities.parser.models import VpcLatticeV2Model


@event_parser(model=VpcLatticeV2Model)
def lambda_handler(event: VpcLatticeV2Model, context):
    print(event.body)

After

from aws_lambda_powertools.utilities.parser import event_parser
from aws_lambda_powertools.utilities.parser.models import VpcLatticeV2Model


@event_parser
def lambda_handler(event: VpcLatticeV2Model, context):
    print(event.body)

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Tom01098 Tom01098 requested a review from a team October 7, 2023 18:38
@boring-cyborg boring-cyborg bot added the tests label Oct 7, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 7, 2023

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 7, 2023
@Tom01098
Copy link
Contributor Author

Tom01098 commented Oct 7, 2023

As event_parser does not take exclusively kwargs, I couldn't find a way to remove the need to call the decorator before wrapping without breaking existing implementations as specified in the original issue. It might be possible to in lambda_handler_decorator, but I didn't have the time to dive into the implementation there.

@leandrodamascena leandrodamascena linked an issue Oct 8, 2023 that may be closed by this pull request
2 tasks
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Tom01098! We really like PR like this, when we can improve the developer experience with simple but useful ideas. Thanks for working on this.

I left some comments and would like to hear your opinion.

@leandrodamascena
Copy link
Contributor

Hi @Tom01098! We are planning to release a version on Friday and would like to include it. Do you think I can fix a few small things and get this PR ready for merging? Thanks

@Tom01098
Copy link
Contributor Author

Hi @Tom01098! We are planning to release a version on Friday and would like to include it. Do you think I can fix a few small things and get this PR ready for merging? Thanks

Hi @leandrodamascena! Feel free to sort this out, I was going to do it this weekend but happy to get it through to the next release. Thanks!

@leandrodamascena
Copy link
Contributor

Hi @Tom01098! We are planning to release a version on Friday and would like to include it. Do you think I can fix a few small things and get this PR ready for merging? Thanks

Hi @leandrodamascena! Feel free to sort this out, I was going to do it this weekend but happy to get it through to the next release. Thanks!

You've done most of the work and we only need to fix two small things. I will push the commit and we will mention you in the Release Notes! Thank you so much, improving the development experience by removing boilerplate code is something we work hard every day.

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Oct 11, 2023
@leandrodamascena leandrodamascena changed the title feat(parser): infer model from type hint if possible feat(parser): infer model from type hint Oct 11, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (bf2df4f) 95.96% compared to head (5c569fe) 95.96%.
Report is 2 commits behind head on develop.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3181   +/-   ##
========================================
  Coverage    95.96%   95.96%           
========================================
  Files          195      195           
  Lines         8381     8386    +5     
  Branches      1562     1563    +1     
========================================
+ Hits          8043     8048    +5     
  Misses         276      276           
  Partials        62       62           
Files Coverage Δ
aws_lambda_powertools/utilities/parser/parser.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leandrodamascena leandrodamascena added the parser Parser (Pydantic) utility label Oct 11, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@leandrodamascena leandrodamascena merged commit 36afcf7 into aws-powertools:develop Oct 12, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 12, 2023

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@Tom01098 Tom01098 deleted the remove-type-duplication-in-event-parser branch October 13, 2023 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation parser Parser (Pydantic) utility size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Remove duplication of type when parsing event
4 participants